﻿
//加载客户信息
function loadCustoms() {
 var id = $("#byid").val();
    $.ajax({
        url:"load",
        data:"id="+id,
        type:"get",
        dataType:"JSON",
        success:function(data){
            console.info(data);
            if(data !== null){
                $("#ff").form('clear').form('load', data.customs);

                $.each(data.hatProvincesList,function (index,value) {
                    $("#province").append("<option>"+value.province+"</option>");
                });
                $.each(data.hatCityList,function (index,value) {
                    $("#city").append("<option>"+value.city+"</option>");
                });
                $.each(data.hatAreasList,function (index,value) {
                    $("#area").append("<option>"+value.area+"</option>");
                });
                $.each(data.customtypeList,function (index,value) {
                    $("#customtypename").append("<option>"+value.configtypename+"</option>");
                });
                $.each(data.cardtypeList,function (index,value) {
                    $("#cardtypename").append("<option>"+value.configtypename+"</option>");
                });

            }else{
                alert("出错了");
            }
        },
        error:function(){
            alert("请求出错");
        }
    })
}


$(function () {
    //点击保存按钮，提交修改的客户信息
    $("#submit").click(function () {
        //获取表单数据
        var formData=$("#ff").serializeArray();
        //转为json
        var obj={};
        $.each(formData,function (index,value) {
            obj[value.name]=value.value;
        });
        $.ajax({
            url:"updateCustoms",
            type:"put",
            data:JSON.stringify(obj),
            contentType: 'application/json',
            dataType:"JSON",
            success:function(result){
                if(result>0){
                    alert("修改成功");
                }else{
                    alert("修改失败");
                }
            },
            error:function(){
                alert("请求出错");
            }
        })
    })

    //点击返回按钮，返回上一级页面
    $("#returnCustomsMag").click(function () {
        location.href = "asCustoms";
    })
})

